<?php
namespace App\Admin\Extra\Search;

class Html{
    
    // 模糊搜索小组件
    public static function likeRedirect($id, $label, $url, $value= ''){
        return view('admin.search.like', ['id' => $id, 'label' => $label, 'url' => $url, 'value'=>$value]);
    }

    public static function button($name, $url, $class = '', $style= null){
        $baseClass = ['btn', 'btn-warning'];        
        if (stripos($class, 'btn-clear') !== false || stripos($class, 'btn-inverse') !== false || stripos($class, 'btn-primary') !== false || stripos($class, 'btn-info') !== false || stripos($class, 'btn-success') !== false || stripos($class, 'btn-default') !== false|| stripos($class, 'btn-danger') !== false) {
            unset($baseClass[1]);
        }

        if (stripos($class, 'btn-clear-all') !== false){
            $baseClass = [];
        }
        
        $baseClass = implode(' ', $baseClass);
        return "<a class='{$baseClass} {$class}' data-url='{$url}' style ='$style'>{$name}</a>";
    }

    //公告根据序号
    public static function deleteinput(){
        return "<span style='font-size: 20px;font-family:Angsana New;'>删除第</span><input href='test' id='test' name='test' style='width: 30px'><span style='font-size: 20px'>个公告</span>";
    }
    //公告根据序号删除
    public static function deleteButton($servername){
        return "<button name='delete' id='delete' onclick='shanchu()' style='height: 33px; background-color: #00a7d0; color: white; border: 0px; width: 40px'>GO</button>
        <script >
        function shanchu(){
            window.location.href = 'http://{$servername}/admin/notice-plat/delete?'+'{$_SERVER['QUERY_STRING']}'+'&id='+$('#test').val();
        }
        </script>
        ";
    }

    // 日期输入框
    public static function dateInput($name, $label = '日期', $class= '', $value = ''){
        return '<label for="'.$name.'">'.$label.'</label><input type="text" class="form-control search-quick" id="'.$name.'" name='.$name.' style="width:150px;" data-attr="'.$name.'" value="'. $value .'">
        <script>$(function(){ laydate.render({ 
            elem: '.$name.' //指定元素
        });})</script>
        ';
    }
    // 普通文本
    public static function input($name, $label = '日期', $class= '', $value = ''){
        return '<label for="'.$name.'">'.$label.'</label><input type="text" class="form-control search-quick" id="'.$name.'" name='.$name.' style="width:150px;" data-attr="'.$name.'" value="'. $value .'">
        ';
    }

    public static function append($content){
        
        if (!is_array($content)) {
            $content = [$content];
        }
        
        foreach ($content as &$item) {
            $item = '<div class="form-group " style="margin-right:5px;">' . $item. '</div>';
        }
        $content = implode('', $content);

        return self::simplePannel($content);
    }

    public static function simplePannel($content){
        $divA = '<div class="panel panel-default "><div class="panel-body form-inline">';
        $divB = '</div></div>';
        return $divA. $content. $divB;
    }

    /**
     *  将百分数 显示成进度条 
     *  @$rate      string          百分数 20%
     *  @$class     string          进度样式颜色
     * */
    public static function processerBar($rate, $rate_txt = null, $class = null)
    {
        $class = $class ?'': 'btn-info';
        $rate_txt =  $rate_txt ? $rate_txt : $rate;
        $html = '<div class="progress">
                    <div class="progress-bar '.$class.'" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="100" style=" width: '.$rate.';color:#6f5499;">
                    '.$rate_txt.'
                    </div>
                </div>';
        return $html;
    }

    public static function pannelSimple($body, $class = null) {
        $class = $class ? : 'btn-default';
        return '<div class="panel panel-warning">
            <div class="panel-body '.$class.'">
            '.$body.'
            </div>
        </div>';
    }

    public static function sjs($url){
        return <<<EOT

<script>
$(function(){
  $(".search-filter").click(function($obj){
    var query = [];
    $(".search-quick").each(function(){
        query.push($(this).data('attr') + "=" + $(this).val());
    })
    query = query.join('&');
    var url = '{$url}';
    var sep = url.indexOf('?') != -1? '&': '?';
    url = url + sep +query;
    $(location).attr('href', url);  
  });

 
});


</script>
EOT;
    }
}
